#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <sys/stat.h>
#include <fcntl.h>

void Daemonization()
{
    signal(SIGPIPE, SIG_IGN);
    signal(SIGCHLD, SIG_IGN);
    if(fork() > 0)//父进程直接关闭，让子进程曾为孤儿进程
    {
        exit(0);
    }
    setsid();
    int devnull = open("/dev/null",O_RDONLY | O_WRONLY);
    if(devnull > 0)
    {
        dup2(0,devnull);
        dup2(1,devnull);
        dup2(2,devnull);
        close(devnull);
    }
    
}